package chd.edu.spzx.manager.service.impl;

import chd.edu.spzx.manager.mapper.ProductSpecMapper;
import chd.edu.spzx.manager.service.ProductSpecService;
import chd.edu.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Zhang Chaoliang
 * create 2023
 */
@Service
public class ProductSpecServiceImpl implements ProductSpecService {

    @Autowired
    private ProductSpecMapper productSpecMapper;

    /**
     * 列表分页查询
     * @return
     */
    @Override
    public PageInfo<ProductSpec> findByPage(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<ProductSpec> productSpecList = productSpecMapper.findByPage();
        PageInfo pageInfo = new PageInfo(productSpecList);
        return pageInfo;
    }

    /**
     * 添加商品规格
     * @param productSpec
     * @return
     */
    @Override
    public void save(ProductSpec productSpec) {
        productSpecMapper.save(productSpec);
    }

    /**
     * 修改商品规格
     * @param productSpec
     * @return
     */
    @Override
    public void updateById(ProductSpec productSpec) {
        productSpecMapper.updateById(productSpec);
    }

    /**
     * 删除商品规格
     * @param id
     * @return
     */
    @Override
    public void deleteById(Long id) {
        productSpecMapper.deleteById(id);
    }

    /**
     * 查询所有商品规格
     * @return
     */
    @Override
    public List<ProductSpec> findAll() {
        return productSpecMapper.findAll();
    }
}
